console.log('初次体验ts===2222333334445555')
let p1 = 123
let p2: string = '123'

function fn1(id: number, age: number): number {
  return id
}

// const a: HTMLAnchorElement = document.createElement('a')

let arr: (number | string)[] = [1, 2, 3, 'a', 'b']

let p3: string | number = 123
p3 = '111'

type S = string | number
let p4: S = '123'
let p5: S = 111
p5 = 666

/* 数组类型 */
let arr2: number[] = [1, 3, 4]
let arr3: (number | string)[] = [1, 3, 4, 'aaa']
let arr4: Array<number> = [1, 2, 3]
let arr5: Array<string> = ['1', '2']
let arr6: Array<string | number> = ['1', '2', 1]
/* 函数定义 */
function fn2(n1: number, n2: number, n3: number): number {
  return n1 + n2 + n3
}
fn2(1, 2, 3)
const fn3 = (n1: number, n2: number): number => {
  return n1 + n2
}
fn3(1, 2)

/* 函数整体定义 */
// const fn4: (n1: number, n2: number) => number = (a, b) => {
//   return a + b
// }
type fn = (n1: number, n2: number) => number
const fn4: fn = (a, b) => {
  return a + b
}
/* void类型 */
function fn5(n1: number): void {
  console.log(n1)
}

/* 函数参数自定义 */
function fn6(n: number = 0, m2?: string, m?: number) {}

fn6(1)
/* 对象类型 */
const obj1: {
  age: number
  name?: string
  hobby?: string[]
  say1: (n1: number, n2: number) => number
  say2(n1: number): number
} = {
  age: 18,
  name: 'jack',
  hobby: ['1', '2'],
  say1(n1, n2) {
    return n1 + n2
  },
  say2(n1) {
    return n1
  },
}

/* #对象类型-类型别名 */

type person = {
  age: number
  name?: string
  hobby?: string[]
  say1: (n1: number, n2: number) => number
  say2(n1: number): number
}
const obj2: person = {
  age: 18,
  name: 'jack',
  hobby: ['1', '2'],
  say1(n1, n2) {
    return n1 + n2
  },
  say2(n1) {
    return n1
  },
}

// function fn7(n1: number): void {
//   console.log(n1)
// }
type Person2 = { age: number; name?: string; hobby?: string[] }
function fn7(object: Person2): void {
  console.log()
}
fn7({ age: 1, name: 'jack', hobby: [] })

/* 接口 */

interface IPerson {
  age: number
  name?: string
  say?: () => number
  say2(): void
}

const objPerson: IPerson = {
  age: 18,
  say2() {},
}

/* 接口继承 */
interface IPoint2D {
  x: number
  y: number
  n?: number
  m?: number
}
// interface IPoint3D {
//   x: number
//   y: number
//   z: number
// }
interface IPoint3D extends IPoint2D {
  z: string
}
const objExtends: IPoint3D = {
  x: 1,
  y: 2,
  z: '2',
}

/* 字面量 */
let str1: 'hello' = 'hello'
const str2 = 'hello ts'

type gender = 'girl' | 'boy'
// let jack: gender = 'girl'
const jack = 'girl'

type Direction = 'top' | 'bottom' | 'left' | 'right'
function Direc(direction: Direction): void {}
Direc('top')

// #目标 */
/*
string
number
boolean
undefined 
null
symbol
object
bigInt
*/

export {}
